package com.atguigu.eduservice.controller.frontcontroller;

import com.atguigu.commonutils.Result;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 课程 前台前端控制器
 * </p>
 *
 * @author testjava
 * @since 2024-06-23
 */
@RestController
@RequestMapping("/eduservice/frontTeacher")
@CrossOrigin
@Slf4j
public class EduTeacherFrontController {
    @Autowired
    EduTeacherService eduTeacherService;
    @Autowired
    EduCourseService eduCourseService;
    //查询前四个热门讲师
    @GetMapping("teacherFrontIndex")
    public Result courseFrontIndex() {
        QueryWrapper<EduTeacher> eduTeacherQueryWrapper = new QueryWrapper<>();
        eduTeacherQueryWrapper.orderByDesc("id");
        eduTeacherQueryWrapper.last("limit 4");
        List<EduTeacher> eduTeacherFrontlist = eduTeacherService.list(eduTeacherQueryWrapper);
        return Result.ok().data("eduTeacherFrontlist", eduTeacherFrontlist);
    }
    //分页查询讲师
    @PostMapping("getTeacherFrontList/{page}/{limit}")
    public Result getTeacherFrontList(@PathVariable long page, @PathVariable long limit) {

        Page<EduTeacher> eduTeacherPage = new Page<>(page, limit);
        Map<String,Object> map = eduTeacherService.getTeacherFrontList(eduTeacherPage);
        return Result.ok().data(map);
    }
    //讲师详情，课程
    @PostMapping("getTeacherFrontInfo/{teacherId}")
    public Result getTeacherFrontInfo(@PathVariable String teacherId) {
        log.info("掉我没有teacherId:{}",teacherId);
        //查询讲师基本信息
        EduTeacher eduTeacher = eduTeacherService.getById(teacherId);
        //查询讲师所讲的课程
        QueryWrapper<EduCourse> eduCourseQueryWrapper = new QueryWrapper<>();
        eduCourseQueryWrapper.eq("teacher_id", teacherId);
        List<EduCourse> list = eduCourseService.list(eduCourseQueryWrapper);

        return Result.ok().data("eduTeacher",eduTeacher).data("courseList",list);

    }





































}
